#include    "printer.h"
#include    "main.h"
#include    <stdio.h>
#include    <stdlib.h>

printer::printer(QObject *parent) :
    QObject(parent)
{
      tty_file.setFileName(COM4);
      if (!tty_file.open(QIODevice::WriteOnly | QIODevice::Text)) perror("print com open failed !");
      codec1 = QTextCodec::codecForName("GB2312");
}


 bool printer::openfile(QString filename)
{
    if(doc.isOpen())   doc.close();
    doc.setFileName( filename);
    if (!doc.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Unbuffered))
    {
        perror("print doc open failed !");
        return FALSE;
    }
}
void printer::print_file(QString filename)
{
    //if(doc.fileName()==filename)    doc.seek(0);
   // else
     openfile(filename);
     tty_file.write(QByteArray::fromHex("0A"));// 0D 回车
     str1=trUtf8(doc.readAll());
     tty_file.write(codec1->fromUnicode(str1));
     tty_file.flush();
}

void printer::print_string(QString str)
{
    tty_file.write(str.toUtf8());
    tty_file.flush();
}
